package com.bootdo;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import com.bootdo.common.utils.SpringContextHolder;

@EnableAutoConfiguration(exclude = { org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class })
@EnableTransactionManagement
@ServletComponentScan
@MapperScan("com.bootdo.*.dao")
@SpringBootApplication
@EnableCaching
public class Application {
	private final static Logger log = LoggerFactory.getLogger(Application.class);

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
		printProjectConfigs();
	}

	private static void printProjectConfigs() {
		try {
			log.info("==============================启动成功==================================");
			InetAddress address = InetAddress.getLocalHost();
			ServerProperties serverProperties = SpringContextHolder.getApplicationContext().getBean(ServerProperties.class);
			DataSourceProperties dataSourceProperties = SpringContextHolder.getApplicationContext().getBean(DataSourceProperties.class);
			log.info("DataBaseUrl：{}", dataSourceProperties.getUrl());
			log.info("DataBaseDriver：{}", dataSourceProperties.getDriverClassName());
			log.info("DataBaseUser：{} / {}", dataSourceProperties.getUsername(), dataSourceProperties.getPassword());
			log.info("HostName：{}", address.getHostName());
			log.info("Run At：http://localhost:{}", serverProperties.getPort());
			log.info("OR");
			log.info("Run At：http://{}:{}", address.getHostAddress(), serverProperties.getPort());
			log.info("=======================================================================");
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
